package main

import "fmt"

func main() {
	s := "abcdefg"
	fmt.Println(s, len(s))
	for i := 0; i < len(s); i++ {
		fmt.Println(s[i])
	}

	for _, ch := range s {
		fmt.Println(ch)

	}
	fmt.Println(s[0] == 'b')

	//声明一个字符数组
	stackChar := []byte{}
	//入栈
	stackChar = append(stackChar, 'a', 'b', 'c')
	fmt.Println(string(stackChar))
	//出栈（本质就是数组切片，去除最后一个元素）
	stackChar = stackChar[:len(stackChar)-1]
	fmt.Println(string(stackChar))

	//声明一个int数组
	queueInt := []int{}
	//入队列
	queueInt = append(queueInt, 2, 7)
	queueInt = append(queueInt, 4, 8)
	fmt.Println(queueInt)
	//出队列
	queueInt = queueInt[1:]
	fmt.Println(queueInt)

}

func isValid(s string) bool {
	stack := []byte{}
	for i := 0; i < len(s); i++ {
		ch := s[i]
		if ch == '(' || ch == '[' || ch == '{' {
			stack = append(stack, ch)
		} else if ch == ')' {
			if stack[len(stack)-1] == '(' {
				stack = stack[:len(stack)-1]
			} else {
				return false
			}
		} else if ch == ']' {
			if stack[len(stack)-1] == '[' {
				stack = stack[:len(stack)-1]
			} else {
				return false
			}
		} else if ch == '}' {
			if stack[len(stack)-1] == '{' {
				stack = stack[:len(stack)-1]
			} else {
				return false
			}
		}
	}
	return len(stack) == 0
}
